#include <bits/stdc++.h>

using namespace std;
int t;
int n, m, l, v;
struct car {
    int d, v0, a;
} c[120000];
int p[120000];

int main() {
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    for (int k = 1; k <= t; k++) {
        cin >> n >> m >> l >> v;
        bool sp_a = true;
        for (int i = 1; i <= n; i++) {
            cin >> c[i].d >> c[i].v0 >> c[i].a;
            if (c[i].a != 0) {
                sp_a = false;
            }
        }
        for (int i = 1; i <= m; i++) {
            cin >> p[i];
        }
        sort(p + 1, p + m + 1);
        if (sp_a) {
            int osc = 0;
            for (int i = 1; i <= n; i++) {
                if (p[m] >= c[i].d && c[i].v0 > v) {
                    osc++;
                }
            }
            cout << osc << " ";
            if (osc == 0) {
                cout << m << endl;
            } else {
                cout << m - 1 << endl;
            }
        }
    }
    return 0;
}

